package com.zynn.service.module.canal.service.impl;/**
 * @Auther: 刘猛
 * @Date: 2018/10/9 16:17
 * @Description:
 */

import com.zynn.common.core.utils.TypeConvertUtil;
import com.zynn.feign.module.es.SyncEventFeignService;
import com.zynn.message.queue.constant.MqQueueNameConstant;
import com.zynn.message.queue.service.ScheduleMessagePostProcessor;
import com.zynn.message.queue.service.SenderService;
import com.zynn.service.module.canal.service.UserShareEventRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Objects;

/**
 *@ClassName UserShareEventRecordServiceImpl
 *@Description TODO
 *@Author 刘猛
 *@Date 2018/10/9 16:17
 **/

@Service
@Slf4j
public class UserShareEventRecordServiceImpl implements UserShareEventRecordService {

    @Autowired
    SyncEventFeignService syncEventFeignService;

    @Autowired
    private SenderService senderService;

    @Override
    public void handleInsert(Map<String, Object> columnsMap) {
        senderService.send(MqQueueNameConstant.FIND_FRIEND_USER_SHARE_EVENT_RECORD, columnsMap,new ScheduleMessagePostProcessor(1000L,0L,null,null));
    }

    @JmsListener(destination = MqQueueNameConstant.FIND_FRIEND_USER_SHARE_EVENT_RECORD)
    public void findDegOneFriend(Map<String, Object> columnsMap) {
        log.info("FIND_FRIEND_USER_SHARE_EVENT_RECORD:{}", columnsMap);
        /**
         * 分享者id
         */
        Long shareUserId = TypeConvertUtil.objectToLong(columnsMap.get("share_user_id"));
        if(Objects.nonNull(shareUserId)){
            syncEventFeignService.initProcuctFriend(shareUserId);
        }

        /**
         * 被分享者id
         */
        Long beSharedUserId = TypeConvertUtil.objectToLong(columnsMap.get("be_shared_user_id"));
        if(Objects.nonNull(beSharedUserId)){
            syncEventFeignService.initProcuctFriend(beSharedUserId);
        }

    }
}
